************data processing*********
cd E:\data\cooperation\patent\ndata\internet_patent

/*variable list*/
use draft,clear
collin wdi_internetuse yr_sch lpop_dnst fh_ipolity2 hf_efiscore wbgi_pse wbgi_gee ///
ciri_polpris lgdppc wdi_telephone fe_cultdiv taxburden fincialfreedom open monetaryfreedom ///
al_ethnic wdi_trade vdem_corr kun_wiqreco_all urbaniz laborfreedom  ///
fh_fotpsc wdi_internetserv fh_rol une_pee al_language

**the main analysis***
use final_sys,clear
/*label the variabls of the data*/
label var lpat_uspt "Log of the patent grants"
label var lpop_dnst "Log of population density (people per sq. km of land area)"
label var wbgi_pse "Political stability"
label var fh_ipolity2 "Level of democracy (Freedom House/Imputed Polity)"
label var hf_efiscore "Economic freedom index"
label var lgdppc "Log of GDP per capita, PPP (constant 2005 international $)"
label var fe_cultdiv "Cultural diversity"
label var wdi_telephone "Telephone lines (per 100 people)"
label var ciri_polpris "Political imprisonment"
label var taxburden "Tax burden"
label var open "Economic openness"
label var wbgi_gee "Government efficiency"
label var yr_sch_ter "Average years of tertiary schooling attained"
label var fincialfreedom "Financial freedom"
label var wdi_internetuse "Internet users (per 100 people)"
label var polit_sys "Political system"
label var bb_int "Fixed broadband subscriptions"
label var ljur_art "Scientific and technical journal articles"
des 
egen id = group(countrycode)
replace regioncode="LCN" if regioncode=="NAC"
gen region=1
label var region "region area"
replace region=1 if regioncode=="EAS"
replace region=2 if regioncode=="ECS"
replace region=3 if regioncode=="LCN"
replace region=4 if regioncode=="MEA"
replace region=5 if regioncode=="SAS"
replace region=6 if regioncode=="SSF"
gen lint_2=wdi_internetuse^2
gen yr_sch_2=yr_sch_ter^2
label var yr_sch_2 "The square of average years of tertiary schooling attained"
label var lint_2 "The square of internet users (per 100 people)"
save internet_patent,repalce


********************main data analysis*******************************************
use internet_patent,clear
xtset id year

/*1.statisitcal description*/
sum lpat_uspt wdi_internetuse yr_sch_ter lpop_dnst fh_ipolity2 hf_efiscore wbgi_pse wbgi_gee ///
ciri_polpris lgdppc wdi_telephone fe_cultdiv taxburden fincialfreedom open  polit_sys bb_int ljur_art /*table 1*/
 
/*collin test*/
collin wdi_internetuse yr_sch_ter lpop_dnst fh_ipolity2 hf_efiscore wbgi_pse wbgi_gee ///
ciri_polpris lgdppc wdi_telephone fe_cultdiv taxburden fincialfreedom open  /*table 2*/

/*unit root test*/
 xtunitroot fisher lpat_uspt, dfuller lags(3) drift


*****fgls****
xtgls lpat_uspt  wdi_internetuse yr_sch_2 lpop_dnst fh_ipolity2 hf_efiscore  ///
wbgi_pse wbgi_gee ciri_polpris lgdppc wdi_telephone fe_cultdiv i.year i.region , panels(hetero)
est store gls

/*non lag*/
xtreg lpat_uspt wdi_internetuse yr_sch_2 lpop_dnst fh_ipolity2 hf_efiscore ///
wbgi_pse wbgi_gee ciri_polpris lgdppc wdi_telephone ,fe 
est store fe
/*random effect*/
xtreg lpat_uspt L.lpat_uspt wdi_internetuse yr_sch_2 lpop_dnst fh_ipolity2 hf_efiscore ///
wbgi_pse wbgi_gee ciri_polpris lgdppc wdi_telephone ,re
est store re
/*lag of the dependent variable*/
xtreg lpat_uspt L.lpat_uspt wdi_internetuse yr_sch_2 lpop_dnst fh_ipolity2 hf_efiscore ///
wbgi_pse wbgi_gee ciri_polpris lgdppc wdi_telephone ,fe 
est store fe1
/*time tread*/
xtreg lpat_uspt L.lpat_uspt wdi_internetuse yr_sch_2 lpop_dnst fh_ipolity2 hf_efiscore ///
wbgi_pse wbgi_gee ciri_polpris lgdppc wdi_telephone i.year, fe
est store fe2
esttab  re fe fe1 fe2 gls, cells(b(star fmt(4)) t(par fmt(2))) /// 
legend label varlabels(_cons Constant) /// 
stats(N r2_a, fmt(0 3) label(N R-squared ))  /*table 3*/

//hausman test based on model 1
hausman fe re,sigmamore
hausman fe1 re,sigmamore 
hausman fe2 fe,sigmamore

**********fe model with different status***********************
xtreg lpat_uspt L.lpat_uspt wdi_internetuse yr_sch_2 lpop_dnst fh_ipolity2  hf_efiscore ///
wbgi_pse wbgi_gee ciri_polpris lgdppc wdi_telephone, fe
est store fe1
xtreg lpat_uspt L.lpat_uspt L.wdi_internetuse yr_sch_2 lpop_dnst fh_ipolity2  hf_efiscore ///
wbgi_pse wbgi_gee ciri_polpris lgdppc wdi_telephone, fe
est store fe2
xtreg lpat_uspt L.lpat_uspt wdi_internetuse lint_2 yr_sch_2 lpop_dnst fh_ipolity2  hf_efiscore ///
wbgi_pse wbgi_gee ciri_polpris lgdppc wdi_telephone, fe
est store fe3
xtreg lpat_uspt L.lpat_uspt wdi_internetuse lint_2 yr_sch_2 lpop_dnst fh_ipolity2  hf_efiscore ///
wbgi_pse wbgi_gee ciri_polpris lgdppc wdi_telephone i.year, fe
est store fe4
esttab fe1 fe2 fe3 fe4, cells(b(star fmt(4)) t(par fmt(2))) /// 
legend label varlabels(_cons constant) /// 
stats(N r2_a, fmt(0 3) label(N R-squared ))  /*table 4*/
**************************group analysis**********************************
*********democracy analysis*****/*table 5*/

replace group=2 if group==1
replace group=1 if group==0
replace group=0 if group==2 //group=0 indicates the high level of democracy

gen group_lpat_uspt=group*wdi_internetuse
 ******high level
xtreg lpat_uspt L.lpat_uspt wdi_internetuse yr_sch_2 lpop_dnst  hf_efiscore ///
wbgi_pse wbgi_gee ciri_polpris lgdppc wdi_telephone if group==1,fe
est store low_demo

******low level
xtreg lpat_uspt L.lpat_uspt wdi_internetuse yr_sch_2 lpop_dnst  hf_efiscore ///
wbgi_pse wbgi_gee ciri_polpris lgdppc wdi_telephone if group==0,fe
est store high_demo

xtreg lpat_uspt L.lpat_uspt group_lpat_uspt wdi_internetuse yr_sch_2 lpop_dnst  hf_efiscore ///
wbgi_pse wbgi_gee ciri_polpris lgdppc wdi_telephone,fe
est store all_demo

**********political system*************

replace polit_sys=2 if polit_sys==1
replace polit_sys=1 if polit_sys==0
replace polit_sys=0 if polit_sys==2 // polit_sys=0 indicates the Parliamentary, and polit_sys=1 indicates the Presidential
gen inter=polit_sys*wdi_internetuse

xtreg lpat_uspt L.lpat_uspt wdi_internetuse yr_sch_2 lpop_dnst fh_ipolity2 hf_efiscore ///
wbgi_pse wbgi_gee ciri_polpris lgdppc wdi_telephone if polit_sys==0,fe
est store Parli
xtreg lpat_uspt L.lpat_uspt wdi_internetuse yr_sch_2 lpop_dnst fh_ipolity2 hf_efiscore ///
wbgi_pse wbgi_gee ciri_polpris lgdppc wdi_telephone if polit_sys==1,fe
est store Presi


xtreg lpat_uspt L.lpat_uspt wdi_internetuse inter yr_sch_2 lpop_dnst fh_ipolity2 hf_efiscore ///
wbgi_pse wbgi_gee ciri_polpris lgdppc wdi_telephone,fe
est store all_sys
esttab   high_demo low_demo all_demo   Parli Presi all_sys, cells(b(star fmt(4)) t(par fmt(2))) /// 
legend label varlabels(_cons constant) /// 
keep (L.lpat_uspt wdi_internetuse group_lpat_uspt inter _cons) ///
stats(N r2_a, fmt(0 3) label(Observations Adj-R-Square))


**************************************robust test*************
//add the control variables
xtreg lpat_uspt L.lpat_uspt wdi_internetuse yr_sch_2 lpop_dnst fh_ipolity2  hf_efiscore ///
wbgi_pse wbgi_gee ciri_polpris lgdppc wdi_telephone, fe
est store fe
xtreg lpat_uspt L.lpat_uspt wdi_internetuse yr_sch_2 lpop_dnst fh_ipolity2 hf_efiscore wbgi_pse ///
wbgi_gee ciri_polpris lgdppc wdi_telephone taxburden fincialfreedom open,fe 
est store fe1
esttab  fe fe1, cells(b(star fmt(4)) t(par fmt(2))) /// 
legend label varlabels(_cons constant) /// 
stats(N r2_a, fmt(0 3) label(Observations Adj-R-Square))

//Substitution variable
gen l_bb_int=log(bb_int)
xtreg ljur_art  wdi_internetuse yr_sch_2 lpop_dnst fh_ipolity2  hf_efiscore ///
wbgi_pse wbgi_gee ciri_polpris lgdppc wdi_telephone, fe
est store reg1
xtreg ljur_art L.wdi_internetuse yr_sch_2 lpop_dnst fh_ipolity2 hf_efiscore wbgi_pse ///
wbgi_gee ciri_polpris lgdppc wdi_telephone ,fe 
est store reg2
xtreg ljur_art wdi_internetuse lint_2 yr_sch_2 lpop_dnst fh_ipolity2 hf_efiscore wbgi_pse ///
wbgi_gee ciri_polpris lgdppc wdi_telephone ,fe 
est store reg3
xtreg lpat_uspt l_bb_int yr_sch_2 lpop_dnst fh_ipolity2  hf_efiscore ///
wbgi_pse wbgi_gee ciri_polpris lgdppc wdi_telephone, fe
est store reg4
xtreg lpat_uspt L.l_bb_int yr_sch_2 lpop_dnst fh_ipolity2  hf_efiscore ///
wbgi_pse wbgi_gee ciri_polpris lgdppc wdi_telephone, fe
est store reg5

esttab  reg1 reg2 reg3 reg4 reg5, cells(b(star fmt(4)) t(par fmt(2))) /// 
legend label varlabels(_cons constant) ///  
keep( wdi_internetuse L.wdi_internetuse l_bb_int lint_2 L.l_bb_int _cons) ///
stats(N r2, fmt(0 3) label(Observations Adj-R-Square))














